fix(aggregator): attribute a midnight-straddling turn's By Activity to today on the all-provider view - #878
Merged
Conversation
…he all-provider view buildDurablePeriod derived the today slice of the multi-day, all-provider headline from the unsliced whole-range parse, so a turn spanning local midnight kept its category and turn count anchored on its yesterday start. The per-call cost and calls bucketed onto today correctly, but By Activity and the JSON daily turn count lost the post-midnight half — categories summed to only the pre-midnight cost while the headline, By Model and By Project were right. Slice the today parse with filterProjectsByDays first, which re-anchors the straddling turn to its surviving today calls, so today's category cost lands on today. Category cost is the sum of the slice's own calls, so day-N + day-N+1 still equals the whole-range total (no over-count); the per-day turn-count split matches the cache side and the documented per-day semantics. Adds a regression test in the straddling-turn conservation suite (mutation-checked: fails on the pre-fix code). Also fills in the CHANGELOG Unreleased entries for the batch (#853, #856, #872, #846/#859, #866/#867, #833).
iamtoruk
force-pushed
the
fix/by-activity-straddle-undercount
branch
from
August 3, 2026 20:46
a2167a5 to
dbdbf46
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A deep audit of the recently-merged batch surfaced one real regression introduced by #853 (midnight-straddling turn slicing): on the all-provider, multi-day headline, a turn spanning local midnight lost the post-midnight half of its By Activity total and its daily turn count, even though the headline cost, calls, By Model, and By Project were all correct.
buildDurablePeriodderived today's slice of that view from the unsliced whole-range parse (src/usage-aggregator.ts), so the straddling turn kept its category and turn count anchored on its yesterday start. Call-derived cost/calls bucketed onto today correctly (per #853), but the turn-level category stayed on yesterday and the union then took today from a slice with an empty category map.Fix
Slice the today parse with
filterProjectsByDays(raw, {today})first — the same re-anchoring the provider-filtered path already relies on. That moves the straddling turn's surviving today calls (and its category) onto today. Becauseday-aggregatoraccumulates category cost as the sum of the slice's own calls,day-N + day-N+1still equals the whole-range total (no over-count); the per-day turn-count split matches the cache side and the documented per-day semantics.Verification
turns: 0withcalls: 1; after, By Activity sums to $1.35 and today carriesturns: 1.midnight-straddling turn conservationsuite, mutation-checked (fails on the pre-fix code, passes with it).tscclean; full CLI suite green apart from the two pre-existingparser.test.tsfailures that reproduce onmain.Also
Fills in the
CHANGELOG.md## Unreleasedentries that were missing for the batch (#853, #856, #872, #846/#859, #866/#867, plus a #833 citation).Found via a post-merge audit; headline money was never wrong, so this is a By-Activity / daily-turn-count accuracy fix, not a total.